/**
 * es7 异步编程 async(generator 语法糖) await
 */

 async function foo() {
   return 'aqie'   // 类似 Promise.resolve('aqie')
 }
 console.log(foo())

 function timeout() {
   return new Promise((resolve, rejcet) => {
     setTimeout(() => {
        console.log(1)
        // resolve('a')
        rejcet('b')
     }, 1000)
   })
 }

/*  async function foo2(params) {
   const res = await timeout()
   console.log(res)
   console.log(2)
 }
 foo2() */

 async function foo3(params) {
   return await timeout()
 }
 foo3().then(res => {
   console.log(res)
 }).catch(err => {
   console.log(err)
 })


 import ajax from '../ajax'

 function request(url) {
   return new Promise(resolve => {
     ajax(url, res => {
       resolve(res)
     })
   })
 }

 async function getData(params) {
   const res1 = await request('static/a.json')
   console.log(res1)
   const res2 = await request('static/b.json')
   console.log(res2)
 }

 getData()